package ninder.system.view.beans;

import java.io.IOException;

import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;

import ninder.system.control.VacineMeService;

import org.primefaces.context.RequestContext;


@ManagedBean
@SessionScoped
public class LoginBean {

	private String username;

	private String password;

	private String id_pessoal;

	private String session;
	
	private VacineMeService controle;
	
	private int index;
	
	public LoginBean(){
		
		this.controle = new VacineMeService();
		this.index = 0;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getId_pessoal() {
		return id_pessoal;
	}

	public void setId_pessoal(String id_pessoal) {
		this.id_pessoal = id_pessoal;
	}

	public String getSession() {
		return session;
	}

	public void setSession(String session) {
		this.session = session;
	}
    
	public void login(){
		RequestContext context = RequestContext.getCurrentInstance();
		FacesMessage msg = null;
		boolean loggedIn = false;
		
		String session = controle.login(username, password);
		
		if(!session.trim().equals("")){
			
			msg = new FacesMessage(FacesMessage.SEVERITY_INFO,
					"BEM VINDO!", username);
			try {
				FacesContext.getCurrentInstance().getExternalContext()
						.redirect("homeAdmin.jsf");
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}

	}

	public int getIndex() {
		return index;
	}

	public void setIndex(int index) {
		this.index = index;
	}
	
	
	
}
